<template>
  <div>
    <main>
      <div class="title">
        <span v-if="userBase.testTime"
          >考试日期：{{ userBase.testTime | formatTime }}</span
        >
        <span v-else>考试日期：</span>
        <span>距离考试还剩 {{ testTime | restTime }}天</span>
      </div>
      <div class="h383">
        <div class="h363">
          <div>
            <span class="flx Ocolor bd">
              <span>今日练题数量</span>
              <span class="fz40">{{ userBase.today }}</span>
            </span>
            <span class="flx color999">
              <span>今日练习时长(时)</span>
              <span class="fz40 bd">{{
                Math.floor((userBase.times % 86400) / 3600)
              }}</span>
            </span>
            <span class="flx color999">
              <span>总计练题数量</span>
              <span class="fz40 bd">{{ userBase.total }}</span>
            </span>
          </div>
          <div>
            <span class="flx Ocolor bd">
              <span>已购买课程</span>
              <span class="fz40">{{ userBase.courseNum }}</span>
            </span>
            <span class="flx color999">
              <span>我的佣金(元)</span>
              <span class="fz40 bd">0</span>
            </span>
            <span class="flx color999">
              <span>VIP倒计时(天)</span>
              <span class="fz40 bd">{{ vipEndTime | restTime }}</span>
            </span>
          </div>
        </div>
      </div>
      <!-- 已报课程 -->
      <div class="regcourse">
        <div class="bt">
          <span>已报课程</span>
          <span class="color999">上完直播课，别忘了看回放复习哦～</span>
        </div>
        <div class="h290">
          在这里你可以查看自己已经参与的课程，并且查看相关的课程信息和安排。
          这里的课程回放功能是最实用的啦，你可以在已报课程里管理自己的课程回放。对于没有时间上直播课的同学，可以通过已报课程内的课程回放进行学习。担心老师上课讲的内容太难太快，怕自己跟不上的同学，随时可以暂停的课程回放也可以帮助你更好地理解老师所讲的知识。因为有事情耽误了一段直播的同学，已报课程的回放也是对你最好的补充哦～
          冲刺考试阶段，一边复习预测真题，一边再利用回放过一遍老师上课的重点，可以帮助你一直走在正确的路上哦～
        </div>
      </div>
      <!-- 学习计划 -->
      <div class="studyplan">
        <div class="h400">
          <div class="bt">
            <span>学习计划</span>
            <span class="color999"
              >合理安排学习，可以达到事半功倍的效果哦~</span
            >
          </div>
          <div class="h290">
            无论你是否考过PTE，都可以快速的获得一份适合你的PTE复习计划。
            如果你已经参加过PTE考试，九炸炸会根据你目前的成绩，结合问卷调查和目标分数，为你量身打造学习计划。
            如果你在准备自己的第一场考试，那么九炸炸会通过问卷调查和你的目标分数，结合你自身的情况，打造学习计划。
            科学且适合你的计划可以帮助你有条理的完成每日的任务，按部就班的在考前刷完预测真题。快来领取你自己的专属学习计划吧！
          </div>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import api from '@/config/api'
import { sendPost } from '@/utils/http'
import userUtil from "@/utils/userUtil";
export default {
  data () {
    return {
      userBase: {},
      testTime: '',
      vipEndTime: ''
    }
  },
  methods: {
    getNowFormatDate () {
      var date = new Date();
      var seperator1 = "-";
      var seperator2 = ":";
      var month = date.getMonth() + 1;
      var strDate = date.getDate();
      var strHour = date.getHours()
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      if (strHour >= 0 && strHour <= 9) {
        strHour = "0" + strHour;
      }
      var currentdate = date.getFullYear() + seperator1 + month
        + seperator1 + strDate + " " + strHour + seperator2
        + date.getMinutes() + seperator2 + date.getSeconds();
      return currentdate;
    },

    // tab (date1, date2) {
    //   var oDate1 = new Date(date1);
    //   var oDate2 = new Date(date2);
    //   if (oDate1.getTime() > oDate2.getTime()) {
    //     // console.log('第一个大');
    //   } else {
    //     // console.log('第二个大');
    //   }
    // },
    getUserBase () {
      sendPost(api.getUserBase, {}).then(res => {
        // console.log(res.data);
        this.userBase = res.data
        // this.tab(this.getNowFormatDate(), this.userBase.vipEndtime)
        // this.tab(this.getNowFormatDate(), this.userBase.testTime)

        // 处理vip时间
        if (this.getNowFormatDate() < this.userBase.vipEndtime) {
          // console.log(this.userBase.vipEndtime);
          let vipEndtime = this.userBase.vipEndtime
          this.vipEndTime = vipEndtime
          console.log(vipEndtime);
        } else {
          this.vipEndtime = this.getNowFormatDate()
          // console.log(this.getNowFormatDate());
          let vipEndtime = this.getNowFormatDate()
          console.log(vipEndtime);
          this.vipEndTime = vipEndtime
        }

        // 处理测试时间
        if (this.getNowFormatDate() < this.userBase.testTime) {
          let testTime = this.userBase.testTime
          console.log(testTime);
          this.testTime = testTime
        } else {
          let testTime = this.getNowFormatDate()
          console.log(testTime);
          this.testTime = testTime
        }

      })
    },
    getData () {
      sendPost(api.getUserData, {}).then(res => {
        if (res.success == '0') {
          userUtil.set(res.data)
        } else {
          this.$router.push("toLogin")
        }
      })
    }
  },
  created () {
    this.getData()
    this.getUserBase()
  },
}
</script>

<style lang="less" scoped>
main {
  border-radius: 0.3125rem;
  .title {
    height: 3.75rem;
    line-height: 3.75rem;
    background-color: #ff5e4e;
    font-size: 1.125rem;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #ffffff;
    display: flex;
    justify-content: space-between;
    padding: 0 1.25rem;
    box-sizing: border-box;
  }
  .h383 {
    font-size: 1.25rem;
    height: 23.9375rem;
    background-color: #f7f7f7;
    text-align: center;
    .h363 {
      height: 22.6875rem;
      background-color: #fff;
      div {
        height: 11.34375rem;
        display: flex;
        .flx {
          flex: 1;
          display: flex;
          flex-direction: column;
          padding-top: 3.75rem;
          box-sizing: border-box;
          .fz40 {
            font-size: 2.5rem;
          }
        }
        .color999 {
          color: #999;
        }
        .Ocolor {
          color: #ff5e4e;
        }
        .bd {
          font-weight: bold;
        }
      }
    }
  }
  .regcourse {
    height: 18rem;
    padding: 0 1.25rem;
    .bt {
      height: 5rem;
      line-height: 5rem;
      font-size: 1.25rem;
      color: #333;
      font-weight: bold;
      border-bottom: 1px solid #ededed;
      box-sizing: border-box;
      .color999 {
        color: #999;
        font-size: 1rem;
        margin-left: 0.4375rem;
        font-weight: 400;
      }
    }
    .h290 {
      margin-top: 1.25rem;
      color: #333;
      font-size: 1rem;
      line-height: 2rem;
    }
  }
  .studyplan {
    background-color: #f7f7f7;
    padding-top: 1.25rem;
    box-sizing: border-box;
    .h400 {
      background-color: #fff;
      padding: 0 1.25rem;
      box-sizing: border-box;
    }
    .bt {
      height: 5rem;
      line-height: 5rem;
      font-size: 1.25rem;
      color: #333;
      font-weight: bold;
      border-bottom: 1px solid #ededed;
      box-sizing: border-box;
      .color999 {
        color: #999;
        font-size: 1rem;
        margin-left: 0.4375rem;
        font-weight: 400;
      }
    }
    .h290 {
      margin-top: 1.25rem;
      color: #333;
      font-size: 1rem;
      line-height: 2rem;
    }
  }
}
</style>
